using System;
using System.IO;
using GoldDigger.Models;
using GoldDigger.Screens;
using GoldDigger.Sprites;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#if WINDOWS
using Microsoft.Xna.Framework.Storage;
#endif
using TPL.Xna.Common;

namespace GoldDigger
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class GoldDiggerGame : Game
    {
        private readonly ScreenManager _screenManager;

        public GoldDiggerGame()
        {
            //Set the Windows Phone screen resolution
            var graphics = new GraphicsDeviceManager(this)
                               {
                                   PreferredBackBufferWidth = 800,
                                   PreferredBackBufferHeight = 480,
                               };

            Content.RootDirectory = "Content";

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0);

            //Create a new instance of the Screen Manager
            _screenManager = new ScreenManager(this);
            Components.Add(_screenManager);
            //Components.Add(new GamerServicesComponent(this));
#if WINDOWS

            IsMouseVisible = true;
            _screenManager.AddScreen(new TestScreen());
            //StorageDevice device = Guide.
#else
            graphics.IsFullScreen = true;
            //Add two new screens
            _screenManager.AddScreen(new MainMenuScreen());
#endif
            
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                Exit();

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            base.Draw(gameTime);
        }
    }
}
